﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DDD4Fun.Common
{
    public class CTryFinally
    {
        public static CTryFinallyUser TestUserReturnInTry()
        {
            /*
             来自IL的代码
             CTryFinallyUser user = new CTryFinallyUser
			{
				Name = "Mike"
			};
			CTryFinallyUser result;
			try
			{
				result = user;
			}
			finally
			{
				user.Name = "Rose";
				user = null;
			}
			return result;
             */
            CTryFinallyUser user = new CTryFinallyUser() { Name = "Mike" };
            try
            {
                return user;
            }
            finally
            {
                user.Name = "Rose";
                user = null;

            }
        }

        public static CTryFinallyUser TestUserReturnInTry2()
        {
            /*
             来自IL的代码
             CTryFinallyUser user = new CTryFinallyUser
			{
				Name = "Mike"
			};
			try
			{
			}
			finally
			{
				user.Name = "Rose";
				user = null;
			}
			return user;
             */
            CTryFinallyUser user = new CTryFinallyUser() { Name = "Mike" };
            try
            {
                
            }
            finally
            {
                user.Name = "Rose";
                user = null;

            }

            return user;
        }
    }

    public class CTryFinallyUser
    {
        public string Name {get;set;}
    }
}
